#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Create by zhang
# Create on 2022/6/22 16:30
from typing import List

from domain.report.common.period_enum import PeriodEnum


class PeriodMapper:
    local_xbrl = [(PeriodEnum.first_quarter, 4000), (PeriodEnum.half_year, 1000), (PeriodEnum.three_quarter, 4400), (PeriodEnum.year, 5000)]
    local_zh = [
        (PeriodEnum.first_quarter, ["一季度"]),
        (PeriodEnum.half_year, ["半年"]),
        (PeriodEnum.three_quarter, ["三季度"]),
        (PeriodEnum.year, ["年度"]),
        (PeriodEnum.all, ["一季度", "半年", "三季度", "年度"])
    ]

    @classmethod
    def get_xbrl_period(cls, period:PeriodEnum) -> int:
        for l, r in cls.local_xbrl:
            if l == period:
                return r
        return None

    @classmethod
    def get_local_period_by_xbrl(cls, period:int) -> PeriodEnum:
        for l, r in cls.local_xbrl:
            if r == period:
                return l
        return None

    @classmethod
    def get_zh_period(cls, period:PeriodEnum) -> List[str]:
        for l, z in cls.local_zh:
            if l == period:
                return z

    @classmethod
    def get_local_period(cls, s:str):
        for l, z in cls.local_zh:
            if l != PeriodEnum.all and s in z:
                return l